<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="btn">点击按钮,发送ajax请求</button>

    <script>
      function fn(str) {
        console.log(str)
      }
      btn.onclick = function () {
        // 当点击按钮,需要利用jsonp发请求的时候,动态的创建script标签
        const script = document.createElement('script')
        // 给script添加src属性,确定请求的目标地址
        script.src = 'http://localhost:5000/test?callback=fn'

        // 把script添加到dom树上,浏览器会重新解析,从而了发送请求
        document.body.appendChild(script)
      }
    </script>
  </body>
</html>
